﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControls_SiblingMenu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public override void DataBind()
    {
        if (CarbonExchangePage.AcmsContext.CurrentPost != null)
        {
            var data = CarbonExchangePage.AcmsContext.CurrentPost.Parent.Children;
            int selected = data.FindIndex(x => x.Id == CarbonExchangePage.AcmsContext.CurrentPost.Id);
            siblings.SelectedIndex = selected;
            siblings.DataSource = data;
            siblings.DataBind();
        }
    }

    protected PageBase CarbonExchangePage
    {
        get
        {
            var tmp = Page as PageBase;
            if (tmp == null)
            {
                throw new ApplicationException("SiblingMenu can only be used in a page that inherits from PageBase");
            }
            return tmp;
        }

    }

}
